import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';

/// 通用使用本地图片
class XinHeAssetImage extends StatelessWidget {
  /// 图片资源路径
  final String file;
  /// 显示样式
  final BoxFit? fit;
  final double? width;
  final double? height;
  final String? package;

  const XinHeAssetImage(this.file,{
    Key? key,
    this.fit,
    this.width,
    this.height,
    this.package,
  }) : super(key: key);


  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Image(
      image: AssetImage(file,package: package),
      fit: fit??BoxFit.cover,
      width: width,
      height: height,
    );
  }
}




/// 通用使用网络图片
class XinHeNetImage extends StatelessWidget {
  /// 图片资源路径
  final String url;
  /// 显示样式
  final BoxFit? fit;
  /// 宽
  final double? width;
  /// 高
  final double? height;

  final String? placeholderUrl;
  const XinHeNetImage({
    Key? key,
    required this.url,
    this.fit,
    this.width,
    this.height,
    this.placeholderUrl
  }) : super(key: key);


  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return CachedNetworkImage(
      imageUrl: url,
      fit: fit,
      width: width,
      height: height,
      placeholder: (context, url) => placeholderUrl !=null && placeholderUrl!.isNotEmpty? XinHeAssetImage(placeholderUrl!,fit: fit,width: width,height: height,): const CircularProgressIndicator(),
      errorWidget: (context, url, error) => const Icon(Icons.error),
      // cacheManager: EsoImageCacheManager(),
    );
  }
}




/// 通用使用网络图片
ImageProvider KDNetProviderImage({required String url}){
  return CachedNetworkImageProvider(
    url,
    // cacheManager: EsoImageCacheManager(),
  );
}
